﻿using System;
using System.Collections.Generic;
using Dost.Khcn.Data.EntityModel;
using Dost.Khcn.Data.Implements;
using Dost.Khcn.Data.Interfaces;

namespace Dost.Khcn.Biz
{
    public class CoSoDaoTaoBiz
    {
        #region Properties

        private ICoSoDaoTaoDao _csdtDao;
        private ICoSoDaoTaoDao CoSoDaoTaoData
        {
            get { return _csdtDao ?? (_csdtDao = new CoSoDaoTaoDao()); }
        }

        #endregion

        #region Constructors

        #endregion

        #region Methods

        public List<CoSoDaoTao> GetAllCoSoDaoTaos()
        {
            return CoSoDaoTaoData.GetAll();
        }

        public object GetCoSoDaoTaos(int startIndex, int pageSize, string sorting, string name)
        {
            try
            {
                int totalRecords;
                var csdts = CoSoDaoTaoData.GetCoSoDaoTaos(startIndex, pageSize, sorting, name, out totalRecords);
                return new { Result = "OK", Records = csdts, TotalRecordCount = totalRecords };
            }
            catch (Exception ex)
            {
                return new { Result = "ERROR", ex.Message };
            }
        }

        public CoSoDaoTao CreateCoSoDaoTao(CoSoDaoTao csdt)
        {
            // validate inputs
            if (csdt == null) return null;

            return string.IsNullOrEmpty(csdt.Ten) ? null : CoSoDaoTaoData.AddCoSoDaoTao(csdt);
        }

        public CoSoDaoTao GetById(int id)
        {
            return id > 0 ? CoSoDaoTaoData.GetById(id) : null;
        }

        public void UpdateCoSoDaoTao(CoSoDaoTao csdt)
        {
            if (csdt == null) return;

            CoSoDaoTaoData.UpdateCoSoDaoTao(csdt);
        }

        public object DeleteCoSoDaoTao(int id)
        {
            try
            {
                CoSoDaoTaoData.DeleteCoSoDaoTao(id);
                return new { Result = "OK" };
            }
            catch (Exception ex)
            {
                return new { Result = "ERROR", ex.Message };
            }
        }

        #endregion
    }
}
